package com.youlu.campus.admin.card.controller;

import com.youlu.campus.admin.card.dto.CardCategoryDeleteDTO;
import com.youlu.campus.admin.card.dto.CardCategorySaveDTO;
import com.youlu.campus.admin.card.dto.CardCategorySearchDTO;
import com.youlu.campus.admin.card.service.CardCategoryService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : [dengbo]
 * @className : CardCategoryController
 * @description : [会员卡分类]
 * @createTime : [2022/12/16 21:44]
 */
@Slf4j
@RestController
@RequestMapping("/ts-card/")
public class CardCategoryController {
    @Autowired
    private CardCategoryService cardCategoryService;

    /**
     * 会员卡分类 分类列表
     * @param searchDto
     * @return
     */
    @PostMapping("/category/list")
    public QResult list(@RequestBody CardCategorySearchDTO searchDto) {
        return QResult.success(cardCategoryService.list(searchDto));
    }

    /**
     * 获取所有一级分类 分类列表
     * @return
     */
    @PostMapping("/category/all")
    public QResult all() {
        return QResult.success(cardCategoryService.all());
    }

    /**
     * 分类保存
     * @param dto
     * @return
     */
    @PostMapping("/category/save")
    public QResult save(@Validated @RequestBody CardCategorySaveDTO dto) {
        return QResult.success(cardCategoryService.save(dto));
    }

    /**
     * 分类删除
     * @param request
     * @return
     */
    @PostMapping("/category/delete")
    public QResult list(@Validated @RequestBody CardCategoryDeleteDTO request) {
        return QResult.success(cardCategoryService.delete(request));
    }
}
